﻿CREATE FUNCTION [dbo].[fn_ColumnsAndAttributes]
(
	@Table sysname
)
RETURNS TABLE
AS
	RETURN (
	    SELECT ColumnName AS 'ColumnName',
	           dbo.fn_QuoteName(ColumnName) AS 'QuotedColumnName',
	           '@' + REPLACE(ColumnName, ' ', '') AS 'VariableColumnName',
	           dbo.fn_ColumnDatatype(@Table, ColumnName) AS 'Datatype',
	           dbo.fn_ColumnMaxLength(@Table, ColumnName) AS 'MaxLength',
	           dbo.fn_ColumnIsIdentity(@Table, ColumnName) AS 'IsIdentity',
	           dbo.fn_ColumnIsTimestamp(@Table, ColumnName) AS 'IsTimestamp',
	           dbo.fn_ColumnIsComputed(@Table, ColumnName) AS 'IsComputed',
	           dbo.fn_ColumnIsPartOfPrimaryKey(@Table, ColumnName) AS 'IsPartOfPrimaryKey',
	           dbo.fn_ColumnIsNullable(@Table, ColumnName) AS 'IsNullable',
	           dbo.fn_NumericPrecision(@Table, ColumnName) AS 'NumericPrecision',
	           dbo.fn_NumericScale(@Table, ColumnName) AS 'NumericScale'
	    FROM   dbo.fn_Columns(@Table)
	)